home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / MacTextBorder.java < prev    next >
Text File  |  1998-06-30  |  3KB  |  119 lines

  1. /*
  2.  * @(#)MacTextBorder.java    1.6 98/02/02
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21.  
  22. package com.sun.java.swing.plaf.mac;
  23.  
  24. import java.awt.Graphics;
  25. import java.awt.Insets;
  26. import java.awt.Rectangle;
  27. import java.awt.Color;
  28. import java.awt.Component;
  29.  
  30. import com.sun.java.swing.*;
  31. import com.sun.java.swing.border.*;
  32. import com.sun.java.swing.plaf.*;
  33.  
  34.  
  35. /**
  36.  * Draws the Mac Text border.
  37.  * <p>
  38.  * Warning: serialized objects of this class will not be compatible with
  39.  * future swing releases.  The current serialization support is appropriate
  40.  * for short term storage or RMI between Swing1.0 applications.  It will
  41.  * not be possible to load serialized Swing1.0 objects with future releases
  42.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  43.  * baseline for the serialized form of Swing objects.
  44.  *
  45.  * @version @(#)MacTextBorder.java    1.0 11/24/97
  46.  * @author Symantec
  47.  */
  48. public class MacTextBorder extends AbstractBorder implements UIResource
  49.   {
  50.     final static Insets borderInsets = new Insets(3, 3, 3, 3);
  51.     final static Insets noInsets = new Insets(0, 0, 0, 0);
  52.     
  53.     private Color black = MacUtilities.GrayscaleAppearanceB;
  54.     private Color white = MacUtilities.GrayscaleAppearanceW;
  55.     private Color macFive = MacUtilities.GrayscaleAppearance5;
  56.     private Color macEight = MacUtilities.GrayscaleAppearance8;
  57.     
  58.        boolean containedInScrollPane = false;
  59.       
  60.     public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) 
  61.     {
  62.         //don't draw the border if inside a scroll pane
  63.         Component parent = c.getParent();
  64.         while(parent != null) 
  65.         {
  66.             if(parent instanceof JScrollPane)
  67.                 return;
  68.                 
  69.             parent = parent.getParent();
  70.         }
  71.                     
  72.            boolean ownsFocus = false;
  73.  
  74.         ownsFocus = ((com.sun.java.swing.JComponent)c).hasFocus();
  75.         
  76.         if(ownsFocus == true)
  77.         {
  78.             g.setColor(black);
  79.             g.drawRect(2, 2, w-5, h-5);
  80.             
  81.             java.awt.Color color = AppearanceFilter.FilterColor(macEight);
  82.             g.setColor(color);
  83.             g.drawRect(1, 1, w-3, h-3);
  84.             g.drawLine(1, 0, w-2, 0);
  85.             g.drawLine(0, 1, 0, h-2);
  86.             g.drawLine(1, h-1, w-2, h-1);
  87.             g.drawLine(w-1, 1, w-1, h-2);
  88.         }
  89.         else
  90.         {
  91.             g.setColor(black);
  92.             g.drawRect(2, 2, w-5, h-5);
  93.             
  94.             g.setColor(macFive);
  95.             g.drawLine(1, 1, w-3, 1);
  96.             g.drawLine(1, 1, 1, h-3);
  97.             
  98.             g.setColor(white);
  99.             g.drawLine(w-2, 2, w-2, h-2);
  100.             g.drawLine(2, h-2, w-3, h-2);
  101.         }
  102.     }
  103.     
  104.     public Insets getBorderInsets(Component c)
  105.     {
  106.         //no border if inside a scroll pane
  107.         Component parent = c.getParent();
  108.         while(parent != null)
  109.         {
  110.             if(parent instanceof JScrollPane)
  111.                  return noInsets;
  112.                  
  113.             parent = parent.getParent();
  114.         }
  115.  
  116.         return borderInsets;
  117.     }
  118. }
  119.